package com.fengke.dao.order.impl;

import java.sql.SQLException;
import java.util.List;

import com.fengke.dao.BaseDaoIbatis;
import com.fengke.dao.model.OrderItemModel;
import com.fengke.dao.model.OrderModel;
import com.fengke.dao.model.PaymentModel;
import com.fengke.dao.order.OrderManager;

public class OrderManagerImpl extends BaseDaoIbatis implements OrderManager {

	public Integer researchOrderListSize(OrderModel orderModel) throws SQLException {
		return (Integer) this.getSqlMapClientTemplate().queryForObject("OrderRepository.researchOrderModelListSize", orderModel);
	}

	@SuppressWarnings("unchecked")
	public List<OrderModel> researchOrderList(OrderModel orderModel, int offset, int limit) throws SQLException {
		return this.getSqlMapClientTemplate().queryForList("OrderRepository.researchOrderModelList", orderModel, offset, limit);
	}

	public OrderModel researchOrderById(OrderModel orderModel) throws SQLException {
		return (OrderModel) this.getSqlMapClientTemplate().queryForObject("OrderRepository.researchOrderModelById", orderModel);
	}

	@SuppressWarnings("unchecked")
	public List<OrderItemModel> researchOrderItemListByOrderId(OrderItemModel orderItem) throws SQLException {
		return this.getSqlMapClientTemplate().queryForList("OrderRepository.researchOrderItemListByOrderId", orderItem);
	}

	public Integer researchPayMentListSize(PaymentModel paymentModel) throws SQLException {
		return (Integer) this.getSqlMapClientTemplate().queryForObject("OrderRepository.researchPaymentModelListSize", paymentModel);
	}

	@SuppressWarnings("unchecked")
	public List<PaymentModel> researchPaymentList(PaymentModel paymentModel, int offset, int limit) throws SQLException {
		return this.getSqlMapClientTemplate().queryForList("OrderRepository.researchPaymentModelList", paymentModel, offset, limit);
	}

	public PaymentModel researchPaymentById(PaymentModel paymentModel) throws SQLException {
		return (PaymentModel) this.getSqlMapClientTemplate().queryForObject("OrderRepository.researchPaymentModelById", paymentModel);
	}

	@Override
	public Long createOrder(OrderModel orderModel) throws SQLException {
		return (Long) this.getSqlMapClientTemplate().insert("OrderRepository.createOrder", orderModel);
	}

	@Override
	public Long createOrderItem(OrderItemModel orderItem) throws SQLException {
		return (Long) this.getSqlMapClientTemplate().insert("OrderRepository.createOrderItem", orderItem);
	}

	@Override
	public Long createPayment(PaymentModel paymentModel) throws SQLException {
		return (Long) this.getSqlMapClientTemplate().insert("OrderRepository.createPayment", paymentModel);
	}

	@Override
	public void updateOrderModelPaymentStatus(OrderModel orderModel) throws SQLException {
		this.getSqlMapClientTemplate().update("OrderRepository.updateOrderModelPaymentStatus", orderModel);
	}

	@Override
	public void updatePaymentModelStatus(PaymentModel paymentModel) throws SQLException {
		this.getSqlMapClientTemplate().update("OrderRepository.updatePaymentModelStatus", paymentModel);
	}

	@Override
	public void updateTimeoutNopaidOrder(OrderModel orderModel) throws SQLException {
		this.getSqlMapClientTemplate().update("OrderRepository.updateTimeoutNopaidOrder", orderModel);
	}

	@Override
	public void deleteOrderItemByOrderIds(List<String> list) throws SQLException {
		this.getSqlMapClientTemplate().delete("OrderRepository.deleteOrderItemModelByOrderIds", list);
	}

	@Override
	public void deletePaymentByOrderIds(List<String> list) throws SQLException {
		this.getSqlMapClientTemplate().delete("OrderRepository.deletePaymentModelByOrderIds", list);
	}

	@Override
	public void deleteOrderByIds(List<String> list) throws SQLException {
		this.getSqlMapClientTemplate().delete("OrderRepository.deleteOrderModelByIds", list);
	}

	@Override
	public void updateOrderModelStatus(OrderModel orderModel) throws SQLException {
		this.getSqlMapClientTemplate().update("OrderRepository.updateOrderModelStatus", orderModel);
	}

	@Override
	public void updateAssociateShowStatus(OrderModel orderModel) throws SQLException {
		this.getSqlMapClientTemplate().update("OrderRepository.updateAssociateShow", orderModel);
	}

}
